package org.smartboot.flow.core.parser;

import org.smartboot.flow.core.parser.definition.AdapterDefinition;
import org.smartboot.flow.core.parser.definition.ChooseDefinition;
import org.smartboot.flow.core.parser.definition.ElementDefinition;
import org.smartboot.flow.core.parser.definition.EngineDefinition;
import org.smartboot.flow.core.parser.definition.IfElementDefinition;
import org.smartboot.flow.core.parser.definition.PipelineComponentDefinition;
import org.smartboot.flow.core.parser.definition.PipelineDefinition;

/**
 * @author qinluo
 * @date 2022-11-15 20:15:34
 * @since 1.0.0
 */
public interface DefinitionVisitor {

    /**
     * Visit element definition.
     *
     * @param ed element definition.
     */
    void visit(ElementDefinition ed);

    /**
     * Visit engine element.
     *
     * @param ed element definition.
     */
    void visit(EngineDefinition ed);

    /**
     * Visit pipeline element
     *
     * @param ed element definition.
     */
    void visit(PipelineDefinition ed);

    void visit(PipelineComponentDefinition ed);

    void visitBasic(ElementDefinition ed);

    void visit(IfElementDefinition ed);

    void visit(ChooseDefinition ed);

    void visit(AdapterDefinition adapterDefinition);

    /**
     * Init visitor with parse ctx.
     *
     * @param ctx ctx.
     * @since 1.0.4
     */
    default void init(ParserContext ctx) {

    }

    /**
     * Return rollback script name of name.
     *
     * <p>
     *     initScript --> initScript-rollback.
     *     reduceStock --> reduceStock-rollback.
     *
     * </p>
     *
     * @param name name
     * @return     rollback name
     */
    default String getRollbackScriptName(String name) {
        return name + "-rollback";
    }
}
